﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class ChildrenBLL : IChildrenBLL
    {
        private static readonly IChildrenDAL dal = DataAccess.CreateChildrens();

        private EmployeeInfo empInfo = new EmployeeInfo();
        private HisSpouseInfo spouInfo = new HisSpouseInfo();
        private PersonInfo perInfo = new PersonInfo();
        private MasGenderInfo genderInfo = new MasGenderInfo();
        private MasNamePrefixInfo prefixInfo = new MasNamePrefixInfo();
        private MasEducationDegreeInfo degreeInfo = new MasEducationDegreeInfo();
        private MasEducationInstituteInfo insInfo = new MasEducationInstituteInfo();

        public DataSet LoadChildrens(Nullable<int> Sequence, Nullable<int> EmployeeSequence)
        {
            return dal.LoadChildrens(Sequence, EmployeeSequence);
        }
        public IList<ChildrenInfo> ListChildrens(string Employee)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            return dal.ListChildrens(new ChildrenInfo(0, 0, null, false, "", "", spouInfo, "", empInfo, null
                , degreeInfo, insInfo, "", null, null));
        }
        public IList<ChildrenInfo> ListChildrensBySequence(int Sequence)
        {
            return dal.ListChildrens(new ChildrenInfo(Sequence));
        }
        public void Insert(string Employee, int ChildNo, string Gender, string NamePrefixes, string FirstName
                , string LastName, Nullable<DateTime> BirthDate, string Status
                , Nullable<DateTime> DeathDate, string DeathRefNo, string EducationStatus
                , Nullable<DateTime> FeeDateEnd, bool FeeEdu, string Spouses, string EduDegree
                , string EduInstitute, string ChildType, string Citizen, int CreatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            spouInfo.Sequence = Spouses.Length > 0 ? Int32.Parse(Spouses) : 0;
            genderInfo.Sequence = Gender.Length > 0 ? Int32.Parse(Gender) : 0;
            prefixInfo.Sequence = NamePrefixes.Length > 0 ? Int32.Parse(NamePrefixes) : 0;
            degreeInfo.Sequence = EduDegree.Length > 0 ? Int32.Parse(EduDegree) : 0;
            insInfo.Sequence = EduInstitute.Length > 0 ? Int32.Parse(EduInstitute) : 0;

            perInfo.BirthDate = BirthDate;
            perInfo.FirstName = FirstName;
            perInfo.LastName = LastName;
            perInfo.Gender = genderInfo;
            perInfo.NamePrefix = prefixInfo;
            perInfo.Citizen = Citizen;
            perInfo.DeathDate = DeathDate;
            perInfo.DeathRefNo = DeathRefNo;

            try
            {
                dal.Insert(new ChildrenInfo(0, ChildNo, FeeDateEnd, FeeEdu, Status, EducationStatus
                    , spouInfo, ChildType, empInfo, perInfo, degreeInfo, insInfo, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Update(int Sequence, string Employee, int ChildNo, string Gender, string NamePrefixes, string FirstName
                , string LastName, Nullable<DateTime> BirthDate, string Status
                , Nullable<DateTime> DeathDate, string DeathRefNo, string EducationStatus
                , Nullable<DateTime> FeeDateEnd, bool FeeEdu, string Spouses, string EduDegree
                , string EduInstitute, string ChildType, string Citizen, int UpdatedBy)
        {
            empInfo.Sequence = Employee.Length > 0 ? Int32.Parse(Employee) : 0;
            spouInfo.Sequence = Spouses.Length > 0 ? Int32.Parse(Spouses) : 0;
            genderInfo.Sequence = Gender.Length > 0 ? Int32.Parse(Gender) : 0;
            prefixInfo.Sequence = NamePrefixes.Length > 0 ? Int32.Parse(NamePrefixes) : 0;
            degreeInfo.Sequence = EduDegree.Length > 0 ? Int32.Parse(EduDegree) : 0;
            insInfo.Sequence = EduInstitute.Length > 0 ? Int32.Parse(EduInstitute) : 0;

            perInfo.BirthDate = BirthDate;
            perInfo.FirstName = FirstName;
            perInfo.LastName = LastName;
            perInfo.Gender = genderInfo;
            perInfo.NamePrefix = prefixInfo;
            perInfo.Citizen = Citizen;
            perInfo.DeathDate = DeathDate;
            perInfo.DeathRefNo = DeathRefNo;

            try
            {
                dal.Update(new ChildrenInfo(Sequence, ChildNo, FeeDateEnd, FeeEdu, Status, EducationStatus
                    , spouInfo, ChildType, empInfo, perInfo, degreeInfo, insInfo, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
